var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var BundleConfig = require("AA_BundleConfig");
var EventManager = require("AA_EventManager");
var ResKeeper = require("AA_ResKeeper");
var CommonUtils = require("AA_CommonUtils");
var EvenType = require("AA_EvenType");
var Excel = require("AA_Excel");
var GameGlobalVariable = require("AA_GameGlobalVariable");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;

var _def_UI_AttackTongJi = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.scroll = null;
    t.tipTongji = null;
    t.maxvalue = 1e4;
    t.ids = 0;
    return t;
  }
  __extends(_creator, e);
  _creator.prototype._show = function (e) {
    var t = [];
    for (var o = 1; o < arguments.length; o++) {
      t[o - 1] = arguments[o];
    }
  };
  _creator.prototype.onEnable = function () {
    EventManager.EventMgr.addEventListener(EvenType.EVENT_TYPE.GAME_SHANGHAI_TONGJI, this.onShangHaiTong, this);
    EventManager.EventMgr.addEventListener(EvenType.EVENT_TYPE.HIDE_CLICK, this.onHideClick, this);
    this.hideTongji();
  };
  _creator.prototype.onHideClick = function (e) {
    2 == e && this.hideTongji();
  };
  _creator.prototype.onDisable = function () {
    EventManager.EventMgr.rmEventListener(EvenType.EVENT_TYPE.HIDE_CLICK, this.onHideClick, this);
    EventManager.EventMgr.rmEventListener(EvenType.EVENT_TYPE.GAME_SHANGHAI_TONGJI, this.onShangHaiTong, this);
  };
  _creator.prototype.showTongJi = function () {
    if (this.tipTongji.active) {
      this.hideTongji();
    } else {
      this.tipTongji.active = true;
      this.tipTongji.scale = 0;
      cc.tween(this.tipTongji).to(.1, {
        scale: 1
      }).start();
      EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.GAME_SHOW_CLICK, 2);
      this.onShangHaiTong();
    }
  };
  _creator.prototype.hideTongji = function () {
    var e = this;
    this.tipTongji.active && cc.tween(this.tipTongji).to(.1, {
      scale: 0
    }).call(function () {
      e.tipTongji.active = false;
    }).start();
  };
  _creator.prototype.onShangHaiTong = function () {
    return __awaiter(this, undefined, undefined, function () {
      var e;
      var t;
      var o;
      var n;
      var i;
      var a;
      var r;
      var c;
      var l;
      var d;
      var h;
      var _;
      var m;
      var y;
      var v;
      var b;
      var w;
      var I;
      var E;
      return __generator(this, function (s) {
        switch (s.label) {
          case 0:
            e = this.scroll.content.children;
            t = (t = Object.keys(GameGlobalVariable.GameGlobalVariable.nowwShangHai)).sort(function (e, t) {
              if (GameGlobalVariable.GameGlobalVariable.nowwShangHai[e] > GameGlobalVariable.GameGlobalVariable.nowwShangHai[t]) {
                return -1;
              } else {
                return 1;
              }
            });
            this.ids = 0;
            o = 0;
            for (a = 0; a < t.length; a++) {
              n = t[a];
              i = GameGlobalVariable.GameGlobalVariable.nowwShangHai[n];
              o += i;
            }
            a = 0;
            s.label = 1;
          case 1:
            if (a < 5) {
              r = t[a];
              c = e[a];
              if (r) {
                if (!c) {
                  c = cc.instantiate(e[0]), this.scroll.content.addChild(c);
                }
                c.active = true;
                l = c.children[0].getComponent(cc.Sprite);
                d = Excel.Excel.shuiguo(1e3 + Number(r));
                return [4, this._loadRes(BundleConfig.BundleNames.Game, "game/" + "res/tongji" + d.quality, cc.SpriteFrame)];
              } else {
                return [3, 6];
              }
            } else {
              return [3, 8];
            }
          case 2:
            h = s.sent();
            l.spriteFrame = h;
            _ = c.children[2].getComponent(cc.Sprite);
            return [4, this._loadRes(BundleConfig.BundleNames.Game, "game/" + "res/tongjipro" + (a + 1), cc.SpriteFrame)];
          case 3:
            m = s.sent();
            _.spriteFrame = m;
            if ((y = c.children[1].getComponent(cc.Sprite)).name == r) {
              return [3, 5];
            } else {
              return [4, this._loadRes(BundleConfig.BundleNames.Common, "common/" + "res/player/player" + r + "_1", cc.SpriteFrame)];
            }
          case 4:
            v = s.sent();
            y.spriteFrame = v;
            y.node.name = r;
            CommonUtils.default.LimitSpriteMaxSize(y, 60);
            s.label = 5;
          case 5:
            b = c.children[3].getComponent(cc.Label);
            w = GameGlobalVariable.GameGlobalVariable.nowwShangHai[r];
            w = this.formatNumberWithChineseUnit(w);
            b.string = w;
            I = c.children[2];
            E = GameGlobalVariable.GameGlobalVariable.nowwShangHai[r] / o;
            I.width = 250 * E;
            return [3, 7];
          case 6:
            c && (c.active = false);
            s.label = 7;
          case 7:
            a++;
            return [3, 1];
          case 8:
            return [2];
        }
      });
    });
  };
  _creator.prototype.formatNumberWithChineseUnit = function (e) {
    if (e >= 1e8) {
      return (e / 1e8).toFixed(1) + "E";
    } else if (e >= 1e4) {
      return (e / 1e4).toFixed(1) + "W";
    } else {
      return (e + "").split(".")[0];
    }
  };
  __decorate([_property(cc.ScrollView)], _creator.prototype, "scroll", undefined);
  __decorate([_property(cc.Node)], _creator.prototype, "tipTongji", undefined);
  return __decorate([_ccclass], _creator);
}(ResKeeper.default);
exports.default = _def_UI_AttackTongJi;